package zm.irc.weechat;

import org.apache.commons.lang.StringUtils;

import com.alibaba.fastjson.JSONObject;

import zm.irc.ioc.annotation.Service;
import zm.irc.util.HttpUtil;
import zm.irc.util.JsonUtils;



@Service
public class WeechatTokenUtil {
    



    public String getToken(String corpid,String corpsecret){

        if( StringUtils.isEmpty(corpid) || StringUtils.isEmpty(corpsecret)){
            return null;
        }

        String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s";

        String tokenJson = HttpUtil.getJson(String.format(url, corpid,corpsecret), null);

        JSONObject result = JsonUtils.jsonToBean(tokenJson, JSONObject.class);

        return result.getString("access_token");
    }

}
